package Text3;

import java.util.*;

public class Main {
    static int N = 30, M = 100;
    static int[][] f = new int[N][M];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();
        for (int i = 0; i < N; i++) {
            Arrays.fill(f[i], 0x3f3f3f3f);
        }
        f[0][0] = 0;
        for (int i = 0; i < k; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            for (int j = n; j >= 0; j--) {
                for (int l = m; l >= 0; l--) {
                    f[j][l] = Math.min(f[j][l], f[Math.max(0, j - a)][Math.max(0, l - b)] + c);
                }
            }
        }
        System.out.println(f[n][m]);
    }
}
